package cn.fastoo.common.dao.product;
import cn.fastoo.common.entity.product.ProductCategoryAttrgroup;
import cn.fastoo.common.entity.product.ProductCategoryAttrgroupAttr;
import cn.fastoo.common.sampleframe.dao.FastDao;
import cn.fastoo.common.sampleframe.dao.impl.FastDaoImpl;
import cn.fastoo.common.sampleframe.search.Search;
import cn.fastoo.common.sampleframe.springside.Collections3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List;


@Component
@Transactional
public class ProductCategoryAttrgroupAttrDao extends FastDaoImpl<ProductCategoryAttrgroupAttr> implements FastDao<ProductCategoryAttrgroupAttr> {


    @Autowired
    @Qualifier("mainDS")
    private void setJt(DataSource ds){
        this.jt = new JdbcTemplate(ds);
    }

    public Logger logger = LoggerFactory.getLogger(ProductCategoryAttrgroupAttrDao.class);


    public List<String> findProductAttrIdByProductCategoryAttrgroupId(Long productCategoryAttrgroupId){
        List<ProductCategoryAttrgroupAttr> list = find(new Search().addSearchFilter("EQ_productCategoryAttrgroupId",productCategoryAttrgroupId));
        if(Collections3.isEmpty(list)){
            return null;
        }
        List<String> ids = new ArrayList<>();
        for (ProductCategoryAttrgroupAttr pcaa:list) {
            ids.add(pcaa.getProductAttrId().toString());
        }
        return ids;
    }

}
